package test2;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class Test2 {
    public static void main(String[] args) throws Exception {
        //转账案例,开启事务
        Connection connection = DBUtils.getConnection();
        String sqL = "update t_account set balance=? where user=?";
        PreparedStatement ps = connection.prepareStatement(sqL);
        //开启事务
        connection.setAutoCommit(false);
        ps.setString(1, "1500");
        ps.setString(2, "zs");
        ps.executeUpdate();
        ps.setString(1, "2500");
        ps.setString(2, "ls");
        ps.executeUpdate();
        //提交事务
        connection.commit();

        DBUtils.close(connection, ps);
    }
}
